<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img{
            width: 300px;
        }
    </style>
</head>
<body>
    <img src="" alt="" class="lazy-load" data-src="https://wallpapershome.com/images/pages/ico_h/21283.jpg">
    <script>
        //loading图片的url
        const loadingImgUrl = "/img/loading.gif"
        //懒加载图片元素
        const imgEle = document.querySelector('.lazy-load')
        //图片的真实地址，放在data-src熟悉里面
        const imgRealUrl = imgEle.dataset.src
        //设置图片的地址为loading图片
        imgEle.src = loadingImgUrl
        //创建一个新的图片，在内存里面
        const newImg = document.createElement('img')
        //设置图片地址为imgRealUrl
        newImg.src = imgRealUrl
        //内存中虚拟图片加载完毕之后的回调
        newImg.onload = function(){
            imgEle.src = imgRealUrl
        }
    </script>
</body>
</html>